package com.ruoyi.restaurant.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.restaurant.domain.ResCollect;
import com.ruoyi.restaurant.service.IResCollectService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 收藏表Controller
 * 
 * @author zhang
 * @date 2023-12-19
 */
@RestController
@RequestMapping("/restaurant/collect")
public class ResCollectController extends BaseController
{
    @Autowired
    private IResCollectService resCollectService;

    /**
     * 查询收藏表列表
     */
    @PreAuthorize("@ss.hasPermi('restaurant:collect:list')")
    @GetMapping("/list")
    public TableDataInfo list(ResCollect resCollect)
    {
        startPage();
        List<ResCollect> list = resCollectService.selectResCollectList(resCollect);
        return getDataTable(list);
    }

    /**
     * 导出收藏表列表
     */
    @PreAuthorize("@ss.hasPermi('restaurant:collect:export')")
    @Log(title = "收藏表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ResCollect resCollect)
    {
        List<ResCollect> list = resCollectService.selectResCollectList(resCollect);
        ExcelUtil<ResCollect> util = new ExcelUtil<ResCollect>(ResCollect.class);
        util.exportExcel(response, list, "收藏表数据");
    }

    /**
     * 获取收藏表详细信息
     */
    @PreAuthorize("@ss.hasPermi('restaurant:collect:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(resCollectService.selectResCollectById(id));
    }

    /**
     * 新增收藏表
     */
    @PreAuthorize("@ss.hasPermi('restaurant:collect:add')")
    @Log(title = "收藏表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ResCollect resCollect)
    {
        return toAjax(resCollectService.insertResCollect(resCollect));
    }

    /**
     * 修改收藏表
     */
    @PreAuthorize("@ss.hasPermi('restaurant:collect:edit')")
    @Log(title = "收藏表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ResCollect resCollect)
    {
        return toAjax(resCollectService.updateResCollect(resCollect));
    }

    /**
     * 删除收藏表
     */
    @PreAuthorize("@ss.hasPermi('restaurant:collect:remove')")
    @Log(title = "收藏表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(resCollectService.deleteResCollectByIds(ids));
    }
}
